#include <iostream>
#include <vector>
using namespace std;

class A
{
public:
    A(A &rhs) {} // a copy-constructor must be ref.
    // A(A rhs) {}  // wrong, copy's copy's copy...
};

struct X
{
    X() { cout << "X()\n"; }
    X(const X &) { cout << "X(const X&)\n"; }
    X &operator=(const X &)
    {
        cout << "X=(const X&)\n";
        return *this;
    }
    ~X() { cout << "~X()\n"; }
};

void f(X x) {}   // X(const X&)
void f2(X &x) {} // null

int main()
{
    X x;
    cout << "local x's address:" << &x << endl; // memo1
    cout << endl;

    cout << "non ref arg:" << endl;
    f(x); // X(const X&) ~X()
    cout << endl;

    cout << "ref arg:" << endl;
    f2(x);
    cout << endl;

    cout << "new:" << endl;
    X *px = new X;
    cout << endl;

    cout << "push into vector:" << endl;
    vector<X> vx;
    vx.push_back(x);
    cout << "address in the vector：" << &vx.back() << endl; // diff from memo1
    cout << endl;

    cout << "delete:" << endl;
    delete px;
    cout << endl;

    cout << "间接初始化和赋值:" << endl;
    X x2 = x; // X(const X&) ; copy-constructor
    x2 = x;   // X=(const X&); The =function we define.
    cout << endl;
    return 0;
}